package org.springblade.modules.system.controller;

import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.modules.system.entity.FlowerType;
import org.springblade.modules.system.entity.Flowers;
import org.springblade.modules.system.service.FlowerTypeService;
import org.springblade.modules.system.service.FlowersService;
import org.springblade.utils.PageBounds;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

@RestController
@RequestMapping("/flowers")
@AllArgsConstructor
public class FlowersController {

	private FlowersService flowersService;

	//显示列表
	@GetMapping("/showFlowersTable")
	public HashMap<String, Object> showFlowersTable(Flowers flowers, int currentPage, int pageSize){
		HashMap<String, Object> map = new HashMap<>();
		PageBounds<Flowers> pageBounds = flowersService.showFlowersTable(flowers, currentPage, pageSize);
		map.put("data", pageBounds);
		return map;
	}

	//根据id查询
	@GetMapping("/getFlowerById")
	public Object getFlowerById(Integer id){
		Flowers flowers = flowersService.getFlowerById(id);
		return  flowers;
	}

	//修改
	@PostMapping("updateFlower")
	public R updateFlower(Flowers flowers){
        int i = flowersService.updateFlower(flowers);
        return R.status(i>0);
	}

	//添加
	@PostMapping("/addFlower")
	public R addFlower(Flowers flowers){
		int i = flowersService.addFlower(flowers);
		return R.status(i>0);
	}

	//删除
	@PostMapping("/delFlower")
	public R delFlower(Integer id){
		int i = flowersService.delFlower(id);
		return R.status(i>0);
	}

	//批量删除
	@PostMapping("/deleteFlowers")
	public R delFlowers(Integer[] ids){
		int i = flowersService.deleteFlowers(Arrays.asList(ids));
		return R.status(i>0);
	}

	@GetMapping("/selAllFlowerType")
	public HashMap<String, Object> selAllFlowerType(){
		HashMap<String, Object> map = new HashMap<>();
		List<FlowerType> list = flowersService.selAllFlowerType();
		map.put("data", list);
		return map;
	}

}
